package com.eric.controller;
import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.annotation.SaCheckRole;
import cn.dev33.satoken.annotation.SaMode;
import cn.dev33.satoken.util.SaResult;
import com.eric.domain.dto.EquipmentDto;
import com.eric.domain.po.Equipment;
import com.eric.service.IEquipmentService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
/**
 * <p>
 * 设备库存表 前端控制器
 * </p>
 *
 * @author 新哥
 * @since 2024-03-12
 */
@RestController
@RequestMapping("/equipment")

@RequiredArgsConstructor
public class EquipmentController {
    private final IEquipmentService equipmentService;

    //    新添加一批同样的设备
//    @SaCheckRole(value = {"sys:admin","sys:manager","sys:normal"})
    @PostMapping("/saveOne")
    public SaResult saveOne(EquipmentDto equipmentDto, MultipartFile[] eqPhotoList, HttpServletRequest request){
        return equipmentService.saveOneService(equipmentDto,eqPhotoList,request);
//     return null;
    }
    //    @SaCheckRole(value = {"sys:admin","sys:manager","sys:normal"})
    @GetMapping("/getAllByPage")
    public SaResult getAllByPage(Integer current,Integer pageSize){
        return equipmentService.getAllByPageService(current,pageSize);
    }

    @GetMapping("/{id}")
    public SaResult getOneById(@PathVariable("id")Integer id){
        return equipmentService.getOneByIdService(id);
    }

//    @GetMapping("/getByEncode")
//    public SaResult getOneByEncode(String encode){
//        return equipmentService.getOneByEncodeService(encode);
//    }

    //    @SaCheckRole(value = {"sys:admin","sys:manager"})
    @PutMapping("/modifyOne")
    @SaCheckRole(value = {"sys:coder","sys:superAdmin","sys:admin","sys:manager"},mode = SaMode.OR)
    @SaCheckPermission("sys:modify")

    public SaResult modifyOne(EquipmentDto equipmentDto, MultipartFile[] eqPhotoList, HttpServletRequest request,String[] photoList){
        return equipmentService.modifyOneService(equipmentDto,eqPhotoList,request,photoList);
    }
    //    @SaCheckRole(value = {"sys:admin","sys:manager"})
    @DeleteMapping("/{id}")
    @SaCheckRole(value = {"sys:coder","sys:superAdmin","sys:admin","sys:manager"},mode = SaMode.OR)
    public SaResult deleteOneById(@PathVariable("id") Integer id){
        return equipmentService.deleteOneById(id);
    }

//    @GetMapping("/getByLocation")
//    public SaResult getByLocation(Integer current,Integer pageSize,String location){
//        return equipmentService.getByLocation(current,pageSize,location);
//    }
    //  通过材料类型查询，
    @GetMapping("/getByTypeName")
    public SaResult getByTypeName(String typeName,Integer orderBy,Integer current,Integer pageSize){
        return equipmentService.getByTypeName(typeName,orderBy,current,pageSize);
    }

    //    这个接口配合getByTypeName使用，查询数据条数
    @GetMapping("/getCountByTypeName")
    public SaResult getCountByTypeName(String typeName){
        return equipmentService.getCountsByTypeNameService(typeName);
    }

    //    配合分页获取所有数据行接口，获取所有数据行的条数
    @GetMapping("/getAllCounts")
    public SaResult getAllCounts(){
        return equipmentService.getAllCountsService();
    }

    //     下载一个文件接口
//    @GetMapping("/downLoadFile")
//    public void downLoadFile(String fileName, HttpServletResponse response) throws IOException {
//        equipmentService.downLoadFileService(fileName,response);
//    }
    //      下载多个文件接口，并打包层zip文件
    @PostMapping("/downLoadFiles")
    public void downloadFiles(@RequestBody String[] files, HttpServletResponse response) throws IOException {
        equipmentService.downloadFilesService(files,response);
    }

    @GetMapping("/getByEquipmentName")
    public SaResult getByEquipmentName(String equipmentName,Integer current,Integer pageSize){
        return equipmentService.getByEquipmentNameService(equipmentName,current,pageSize);
    }

//    多功能名字查询
    @GetMapping("/getByMultifunction")
    public SaResult getByMultifunction(String name,Integer current,Integer pageSize){
        return equipmentService.getByMultifunctionService(name,current,pageSize);
    }
//    多功能名字查询-数据条数
    @GetMapping("/getCountByMultifunctionName")
    public SaResult getCountByMultifunctionName(String name){
        return equipmentService.getCountByMultifunctionNameService(name);
    }

    @PutMapping("/modifyEquipmentStatus")
    @SaCheckRole(value = {"sys:coder","sys:superAdmin","sys:admin","sys:manager"},mode = SaMode.OR)
    @SaCheckPermission("sys:modify")
    public SaResult modifyEquipmentStatus( Equipment equipment){
        return equipmentService.modifyEquipmentStatusService(equipment);
    }

}
